<template>
	<view class="p-2 bg-white record">
		<view class="bg-white mb-3 flex a-center j-sb input_view">
			<view class="span-10 ">
				<view class="flex j-sb a-center rounded-10" style="border: 1px solid #dadbde;padding: 12rpx 10rpx;"
					@click="showPicker=true">
					<view class="font" style="color: #333;" v-if="query.auditStatus">
						{{dictKey(transferColumns[0],query.auditStatus,'value','label')}}
					</view>
					<view class="font" style="color: #c0c4cc;" v-if="!query.auditStatus">调拨状态</view>

					<u-icon name="arrow-down" color="#c0c4cc" size="14"></u-icon>
				</view>
			</view>
			<view class="p-1"></view>
			<view class="flex-1" @click="showCalendar=true">
				<view class="time" v-if="!query.beginDate">开始时间~结束时间</view>
				<view class="time time2" v-else>{{query.beginDate}}~{{query.endDate}}</view>
			</view>
		</view>

		<view class="p-1" v-if="listsData.length!=0">
			<view class="py-1 px-2 border rounded-10 mb-2" v-for="(item,index) in listsData" :key="index"
				@click="navigateTo('pages/warehouse/product/detail?productCode='+item.productCode)">
				<view class="my-2 text-primary">
					{{dictKey(transferColumns[0],item.auditStatus,'value','label')}}
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">所在仓库：</view>
					<view class="flex-1">{{item.warehouseName}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">商品编码：</view>
					<view class="flex-1">{{item.productCode}}</view>
					<image src="@/static/images/fuzhi.png" mode="widthFix" class="svgmini ml-3"
						@click.stop="utils.setClipboardData(item.productCode)"></image>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">手机型号：</view>
					<view class="flex-1">{{item.phoneModel}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">手机品牌：</view>
					<view class="flex-1">{{item.phoneBrand}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">内存：</view>
					<view>{{item.memory?item.memory:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">颜色：</view>
					<view class="flex-1">{{item.colour?item.colour:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2"> 
					<view class="text-right col-170">IMEI：</view>
					<view class="flex-1">{{item.imei?item.imei:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">机况：</view>
					<view class="flex-1">{{item.subrackDesc?item.subrackDesc:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">调拨时间：</view>
					<view class="flex-1">{{parseTime(item.createTime)}}</view>
				</view>
				<u-gap height="1" bgColor="#eaeaea" marginTop="10rpx" marginBottom="10rpx"></u-gap>

				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">调拨方：</view>
					<view class="flex-1">{{item.originaUserName?item.originaUserName:'--'}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">调拨方仓库：</view>
					<view class="flex-1">{{item.originaWarehouseName}}</view>
				</view>
				<view class="flex j-start a-center my-2">
					<view class="text-right col-170">调入仓库：</view>
					<view class="flex-1">{{item.cashEntrepoWarehouseName}}</view>
				</view>

				<view class="flex j-end a-center my-2"
					v-if="item.auditStatus=='wait'&&item.saleUserId==app_user_info.id">
					<view class="btn" @click.stop="handleAudit(item,'cancel')">取消</view>
				</view>
			</view>
		</view>

		<empty v-else />




		<u-calendar :show="showCalendar" :monthNum="50" :minDate="minDate" :maxDate="maxDate" mode="range"
			@confirm="confirmCalendar" @close="closeCalendar" :allowSameDay="true"></u-calendar>

		<u-picker :show="showPicker" :columns="transferColumns" keyName="label" @confirm="confirmPicker"
			@cancel="cancelSearch"></u-picker>

	</view>
</template>

<script>
	import {
		transferRecordPage,
		allotAudit
	} from '@/common/api/sales.js'
	const d = new Date()
	const year = d.getFullYear()
	let month = d.getMonth() + 1
	month = month < 10 ? `0${month}` : month
	const date = d.getDate()
	export default {
		name: "",
		mixins: [],
		data() {
			return {
				query: {
					auditStatus: '',
					beginDate: '',
					endDate: ''
				},
				showCalendar: false,
				maxDate: `${year+1}-${month}-${date}`,
				minDate: `${year-1}-${month}-${date}`,
				showPicker: false,
				// WAIT("wait","待审核"),
				// PASS("pass", "已调拨"),
				// REJECT("reject", "驳回"),
				// TIMEOUTCANCEL("timeoutCancel", "超时取消"),
				// CANCEL("cancel", "取消");

			}
		},
		onLoad(option) {
			this.searchList();
		},
		onPullDownRefresh() {
			this.searchList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		onReachBottom() {
			if (!this.isLoadMore) {
				this.isLoadMore = true;
				this.query.pageNo += 1;
				this.getLists();
			}
		},
		watch: {},
		computed: {},
		methods: {
			confirmCalendar(val) {
				this.query.beginDate = val[0]
				this.query.endDate = val[val.length - 1];
				this.searchList();
				this.showCalendar = false
			},
			closeCalendar() {
				this.query.beginDate = ''
				this.query.endDate = '';
				this.searchList();
				this.showCalendar = false
			},
			confirmPicker(val) {
				this.query.auditStatus = val.value[0].value;
				this.showPicker = false;
				this.searchList();
			},
			cancelSearch() {
				this.query.auditStatus = '';
				this.showPicker = false;
				this.searchList();
			},

			getLists() {
				transferRecordPage(this.query).then(res => {
					if (res.data && res.data.list.length == 0) {
						let oldLoad = {}
						this.isLoadMore = true;
						oldLoad = Object.assign({}, this.query);
						oldLoad.pageNo = this.query.pageNo;
						this.query = oldLoad
						this.$forceUpdate()
						return
					}

					this.isLoadMore = false;
					let oldList = this.listsData || [];
					oldList.push(...res.data.list);
					this.listsData = oldList
				})
			},
			handleAudit(item, type) {
				let content;
				if (type == 'pass') {
					content = '确定要通审核吗？'
				} else {
					content = '确定要取消审核吗？'
				}
				uni.showModal({
					title: '提示',
					content: content,
					success: res => {
						if (res.confirm) {
							let aleUserId = this.app_user_info.id;
							allotAudit(aleUserId + '/' + item.id + '/' + type).then(res => {
								uni.$u.toast('操作成功');
								this.getSaleList()
							})
						} else if (res.cancel) {

						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.colorF {
		color: #4F4F4F;
	}

	.input_view {
		.u-input {
			padding: 8rpx 10rpx !important;
		}
	}

	.record {
		/deep/.u-tabs__wrapper__nav__item {
			padding: 0 20px !important;
		}
	}

	.time {
		padding: 8rpx 10rpx !important;
		line-height: 24px;
		font-size: 12px;
		border: 1px solid #dadbde;
		border-radius: 6px;
		color: #c0c4cc;
	}

	.time2 {
		color: #333;
	}
</style>